#1.导入request模块
import requests
#创建全局变量
sess = requests.session()
#3定义全局变量IP
ip = "192.168.1.7"
#Restful-GET类型接口
def restful_get():
    rp = sess.request("get","http://"+ip+":8080/pinter/com/phone/10")
    print(rp.json())

#Restful-POST类型接口
def restful_json_post():
    #传json参数，使用json变量进行传参
    json = {"brand":"Huawei","color":"yellow","memorySize":"64G","cpuCore":"8核","price":"8848","desc":"全新上市"}
    rp = sess.request("post","http://"+ip+":8080/pinter/com/phone",json=json)
    print(rp.text)

def restful_put():
    json = {"brand":"Huawei","color":"yellow","memorySize":"64G","cpuCore":"8核","price":"8848","desc":"全新上市"}
    rp = sess.request("put", "http://" + ip + ":8080/pinter/com/phone", json=json)
    print(rp.text)

def restful_delete():
    json = {"brand":"Huawei","color":"yellow","memorySize":"64G","cpuCore":"8核","price":"8848","desc":"全新上市"}
    rp = sess.request("delete", "http://" + ip + ":8080/pinter/com/phone", json=json)
    print(rp.text)
if __name__ == "__main__":
    restful_get()
    restful_json_post()
    restful_put()
    restful_delete()